// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 
// Source File Name:   GTSDifferenceImpl.java

package com.sunwayhorizo.health.hl7.datatypes.common;

import com.sunwayhorizo.health.hl7.datatypes.BL;
import com.sunwayhorizo.health.hl7.datatypes.GTS;
import com.sunwayhorizo.health.hl7.datatypes.IVL_TS;
import com.sunwayhorizo.health.hl7.datatypes.SET_TS;
import com.sunwayhorizo.health.hl7.datatypes.TS;
import com.sunwayhorizo.health.hl7.datatypes.TYPE;


// Referenced classes of package oracle.apps.ctb.hl7.types.common:
//            GTSBase, ANYImpl, GTSHullImpl, IVL_TSImpl, 
//            NullFlavorImpl, TYPEImpl

public class GTSDifferenceImpl extends GTSBase
    implements GTS
{

    public static final String RCS_ID = "$Header: GTSDifferenceImpl.java 115.16.2050.4 2006/02/22 05:18:47 mmoores noship $";
    GTS _minuend;
    GTS _subtrahend;

    public TYPE dataType()
    {
        return com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.GTS;
    }

    protected String generateLiteral()
    {
        StringBuffer stringbuffer = new StringBuffer();
        boolean flag = _minuend.dataType().equal(com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.GTS).isTrue();
        if(flag)
            stringbuffer.append("(");
        stringbuffer.append(_minuend.literal().stringValue());
        if(flag)
            stringbuffer.append(")");
        stringbuffer.append("\\");
        flag = _subtrahend.dataType().equal(com.sunwayhorizo.health.hl7.datatypes.common.TYPEImpl.GTS).isTrue();
        if(flag)
            stringbuffer.append("(");
        stringbuffer.append(_subtrahend.literal().stringValue());
        if(flag)
            stringbuffer.append(")");
        return stringbuffer.toString();
    }

    public static GTSDifferenceImpl valueOf(GTS gts, GTS gts1)
    {
        return new GTSDifferenceImpl(gts, gts1);
    }

    private GTSDifferenceImpl(GTS gts, GTS gts1)
    {
        _minuend = gts;
        _subtrahend = gts1;
    }

    public BL contains(TS ts)
    {
        return _minuend.contains(ts).and(_subtrahend.contains(ts).not());
    }

    public BL contains(SET_TS set_ts)
    {
        return _minuend.contains(set_ts).and(_subtrahend.intersection(set_ts).isEmpty());
    }

    public IVL_TS hull()
    {
        if(((_minuend instanceof IVL_TS) || (_minuend instanceof GTSHullImpl)) && ((_subtrahend instanceof IVL_TS) || (_subtrahend instanceof GTSHullImpl)))
        {
            IVL_TS ivl_ts = _minuend.hull();
            IVL_TS ivl_ts1 = _subtrahend.hull();
            if(ivl_ts.low().isNull().and(ivl_ts.high().isNull()).or(ivl_ts1.low().isNull().and(ivl_ts1.high().isNull())).isTrue())
                return IVL_TSImpl.nullIVL_TS(NullFlavorImpl.NA);
            if(_minuend.contains(_subtrahend).isTrue())
                return ivl_ts;
            else
                return ivl_ts.except(ivl_ts1).hull();
        } else
        {
            throw ANYImpl.newUnsupportedException("GTS", "hull");
        }
    }
}
